
#ifndef MBEAM_MVDR_H
#define MBEAM_MVDR_H

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "dios_ssp_mvdr_macros.h"
#include "dios_ssp_mvdr_win.h"
#include "../dios_ssp_share/dios_ssp_share_typedefs.h"
#include "../dios_ssp_share/dios_ssp_share_rfft.h"
#include "../dios_ssp_share/dios_ssp_share_cinv.h"

#define BN 8

typedef struct
{
	int		m_fs;
	int		m_channels;
	int		m_fft_size;
	int		m_shift_size;
	int		m_delta_angle;
	float	m_sd_factor;
	float	m_sd_eps;
    float	m_rnn_eps;
	float	m_alpha_rnn;
    float   m_alpha_s;
    float   m_alpha_p;
    float   m_alpha_d;
    int     m_L;
    float   m_delta_thres;
	float	m_deta_fs;
	int		m_sp_size;
	int		m_angle_num;
	float	m_beta_rnn;

	// frame index
    int		m_frame_sum;

	// buffer
	float	**m_mch_buffer;
	float	*m_win_data;
	float	*m_re;
	float	*m_im;
	float	*m_re_temp;
	float	*m_im_temp;
	
	// steering
	int		m_gstv_dim;
	float	*m_gstv_re;
	float	*m_gstv_im;
	float	*m_stv_re;
	float	*m_stv_im;
    float *mbeam_stv_re[BN];
    float *mbeam_stv_im[BN];
	
	// rxx  
	int		m_rxx_size;
	float	*m_rxx_in;
	float	*m_irxx_out;

	// rnn
	float	*m_rnn_re;
	float	*m_rnn_im;
	float	*m_irnn_re;
	float	*m_irnn_im;
	
	// capon spectrum
	int		m_angle_pre;

	// sd rnn 	
	float	*m_sd_rnn_re;		
	float	*m_sd_irnn_re;	
	float	*m_sd_irnn_im;
	
	// mvdr
	float	*m_weight_sd_group_re;
	float   *m_weight_sd_group_im;

	// mcra
	float	*m_ns_ps_cur_mic;
	float	*m_ns_theta_cur_mic;
	float	*m_ns_ps;
	float	*m_P;
	float	*m_Ptmp;
	float	*m_Pmin;
	float	*m_pk;
	float	*m_xn_re;
	float	*m_xn_im;

	float	*m_weight_re;	
	float	*m_weight_im;
    float *mbeam_weight_re[BN];
    float *mbeam_weight_im[BN];
	
	float	*m_mvdr_out_re;
	float	*m_mvdr_out_im;	
	float	*m_out_bf;	
    float *mbeam_out_bf[BN];

	PlaneCoord *cood;
	objMVDRCwin *mvdrwin;
	void *mvdrinv;
	void *mvdr_fft;
	float *fft_in;
	float *fft_out;
	float* dist;
}objmbeamMVDR;

/**********************************************************************************
Function:      // dios_ssp_mvdr_init
Description:   // mvdr init
Input:         // ptr_mvdr:
				  sensor_num: microphone number
				  cood: micphone coordinate
Output:        // none
Return:        // success: return mvdr object pointer (void*)ptr_mvdr
				  failure: return NULL
**********************************************************************************/
void dios_ssp_mbeammvdr_init(objmbeamMVDR *ptr_mvdr, int sensor_num, PlaneCoord* cood);

/**********************************************************************************
Function:      // dios_ssp_mvdr_reset
Description:   // mvdr reset
Input:         // ptr_mvdr:
Output:        // none
Return:        // success: return mvdr object pointer (void*)ptr_mvdr
				  failure: return NULL
**********************************************************************************/
void dios_ssp_mbeammvdr_reset(objmbeamMVDR *ptr_mvdr);

/**********************************************************************************
Function:      // dios_ssp_mvdr_process
Description:   // mvdr process
Input:         // ptr_mvdr:
				  in: microphone data
				  angle: micphone sound source angle
Output:        // out: mvdr process result
**********************************************************************************/
int dios_ssp_mbeammvdr_process(objmbeamMVDR *ptr_mvdr, float* in, float* out, int angle);

/**********************************************************************************
Function:      // dios_ssp_mvdr_mcra
Description:   // mcra process
Input:         // ptr_mvdr:
Output:        // none
Return:        // success: return 0
				  failure: return NULL
**********************************************************************************/
int dios_ssp_mbeammvdr_mcra(objmbeamMVDR *ptr_mvdr);

/**********************************************************************************
Function:      // dios_ssp_mvdr_cal_rxx
Description:   // calculate Rxx
Input:         // ptr_mvdr:
Output:        // none
Return:        // success: return 0
				  failure: return NULL
**********************************************************************************/
int dios_ssp_mbeammvdr_cal_rxx(objmbeamMVDR *ptr_mvdr);

/**********************************************************************************
Function:      // dios_ssp_mvdr_cal_weights_adpmvdr
Description:   // calculate mvdr adaptive weight
Input:         // ptr_mvdr:
Output:        // none
Return:        // success: return 0
				  failure: return NULL
**********************************************************************************/
int dios_ssp_mbeammvdr_cal_weights_adpmvdr(objmbeamMVDR *ptr_mvdr);

/**********************************************************************************
Function:      // dios_ssp_mvdr_delete
Description:   // free ptr_mvdr
Input:         // ptr_mvdr
Output:        // none
Return:        // success: return 0
**********************************************************************************/
void dios_ssp_mbeammvdr_delete(objmbeamMVDR *ptr_mvdr);


#endif